
<?php use_stylesheet('forms.css') //load css pf order page   ?>
<?php use_stylesheet('hoverTables.css') //load css of tables  ?>
<div id="nav"><!-- Navigation with tabs -->
    <ul>
        <a href="<?php echo url_for('sales_index_contacts') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_contacts.png') ?>Contacts</li></a>
        <a href="<?php echo url_for('sales_index_orders') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_orders.png') ?>Orders</li></a>
        <a href="<?php echo url_for('sales_index_pnp') ?>"><li class="no_sel"><span style="float: left;"><?php echo image_tag('Icons/ic_menu_products_parts.png') ?></span><span style="float: left; margin: -2px 0 0 0;">Materials</span><span style=" float: left; margin-top: -5px;">&amp; Products</span></li></a>
        <a href="<?php echo url_for('purchase_index') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_purchase.png') ?>Purchase</li></a><!-- SELECTED TAB -->
        <a href="<?php echo url_for('stock_index') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_stock.png') ?>Stock</li></a>
        <a href="<?php echo url_for('admin_index') ?>"><li class="sel"><?php echo image_tag('Icons/ic_menu_stock.png') ?>Admin</li></a>     
    </ul>
</div><!-- end navigation -->
<div id="page"><!-- The page -->
    
        <div class="button"><!-- sales button -->
            <a href="<?php echo url_for('admin_show_sales') ?>">
                <img src="<?php echo image_path('Buttons/bt_sales.png') ?>" onmouseover="this.src='<?php echo image_path('Buttons/bt_sales_hov.png') ?>';" onmouseout="this.src='<?php echo image_path('Buttons/bt_sales.png') ?>';" title="Sales"/>
            </a>
        </div>
         <div class="button"><!-- users button -->
            <a href="<?php echo url_for('sf_guard_user') ?>">
                <img src="<?php echo image_path('Buttons/bt_add_contact.png') ?>" onmouseover="this.src='<?php echo image_path('Buttons/bt_add_contact_hov.png') ?>';" onmouseout="this.src='<?php echo image_path('Buttons/bt_add_contact.png') ?>';" title="Users"/>
            </a>
        </div>
        <div class="button"><!-- users button -->
            <a href="<?php echo url_for('admin/editCompany') ?>">
                <img src="<?php echo image_path('Buttons/bt_add_material.png') ?>" onmouseover="this.src='<?php echo image_path('Buttons/bt_add_material_hov.png') ?>';" onmouseout="this.src='<?php echo image_path('Buttons/bt_add_material.png') ?>';" title="Company"/>
            </a>
        </div>
    
    <fieldset>
        <legend class="bold">Total rough value stock</legend>
        <div>
        <table>
            <tr>
                <td>Material No.</td>
                <td>Name</td>
                <td>Type</td>
                <td>Total Stock</td>
                <td>Last Buy Price</td>
                <td>Stock Value</td>
            </tr>
            <?php $totalStockValue = 0 ?>
            <?php foreach($materials as $material){?>
            <tr>
                <td><?php echo $material->getPartNumber() ?></td>
                <td><?php echo $material->getName() ?></td>
                <td><?php echo $material->getType() ?></td>
                <?php $totalStock = ($material->getStock() + $material->getReserved()) ?>
                <td><?php echo $totalStock ?></td>
                <?php $purchases = PurchaseTable::findLastPrice($material->getId()); ?>
                <td><?php 
                    if($purchases->count() == 0){ 
                        $lastPrice = null; 
                    } else {
                        foreach($purchases as $purchase){
                            $lastPrice = $purchase->getPrice();
                            echo $lastPrice;
                            break;   
                        }    
                    } ?>
                </td>
                <td><?php echo ($totalStock * $lastPrice) ?></td>
            </tr>
            <?php $totalStockValue += ($totalStock * $lastPrice);
            } ?>
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td><?php echo '-------------' ?></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td><?php echo 'Total Stock Value:' ?></td>
                <td><?php echo $totalStockValue ?></td>
            </tr>
        </table>
        </div>
    </fieldset>
</div>